#!/usr/bin/perl -w
use warnings;
use strict;

die << '__USAGE__' unless @ARGV > 0;
       dho - The Decimal, Hexadecimal, Octal Display Utility.
usage: dho /[bB] [ NUM ... ]

`NUM' is interpreted via its prefix:
   0b: Binary integer.
    0: Octal integer.
  1-9: Decimal integer.
   0x: Hexadecimal integer.

The output is in the following format:
  <Input>: <Decimal>, <Hexadecimal>, <Octal>; <Binary>
Where the trailing '; <Binary>' part is controlled with
the switch `/[bB]':

/b     switches 'binary' mode on.
/B     switches 'binary' mode off. (default)

`DHO' utility version 0.24, build 20070405
copyleft zerox (c) 2006, all rights reserved.
__USAGE__

my $binary = 0;
for (@ARGV) {
    s/^\s*(.*)\s*$/$1/;
    if (/^\/(b)$/i) {
        $binary = $1 eq 'b';
    }
    next unless /^\d/;
    my $n = substr($_, 0, 1) eq '0' ? oct $_ : $_;
    printf "$_: %d, 0x%x, 0%o", $n, $n, $n;
    $binary ? printf "; 0b%b\n", $n : print "\n";
}
